home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 23.2 KB | 737 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPullDM.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWPULLDM_H
- #include "FWPullDM.h"
- #endif
-
- #ifndef FWMNUBAR_H
- #include "FWMnuBar.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- //========================================================================================
- // File scope definitions
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwmenu
- #endif
-
- #define FW_kUnattachedMenuID 255
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CPullDownMenu)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CPullDownMenu)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_CPullDownMenu>
- #pragma template FW_TOrderedCollectionIterator<FW_CPullDownMenu>
-
- #endif
-
- //========================================================================================
- // class FW_CPullDownMenu
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_CPullDownMenu)
-
- // This class is archivable, but we provide the archiving implementation in a separate
- // translation unit in order to enable deadstripping of the archiving-related code
- // in parts that do not use archiving with this class.
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev) :
- fMenuID(FW_kUnattachedMenuID)
- {
- FW_CString32 menuTitle(" ");
- this->PrivInitialize(ev, menuTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev, const FW_CString& menuTitle) :
- fMenuID(FW_kUnattachedMenuID)
- {
- this->PrivInitialize(ev, menuTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev,
- FW_PResourceFile &resFile,
- FW_ResourceID resourceID,
- unsigned long stringID) :
- fMenuID(FW_kUnattachedMenuID)
- {
- FW_CString32 menuTitle;
- ::FW_LoadStringByID(ev, resFile, resourceID, FW_kMultiStringRes, stringID, menuTitle);
- this->PrivInitialize(ev, menuTitle);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::FW_CPullDownMenu(Environment* ev, FW_CReadableStream& stream) :
- fMenuID(FW_kUnattachedMenuID)
- {
- FW_CString menuTitle;
- stream >> menuTitle;
-
- this->PrivInitialize(ev, menuTitle);
-
- // ----- Read every items -----
- short count;
- stream >> count;
-
- FW_ASSERT(count>=0 && count <1000); // just a sanity check
-
- for (short i = 0; i < count; i++)
- {
- FW_CMenuItem* menuItem;
- FW_READ_DYNAMIC_OBJECT(stream, &menuItem, FW_CMenuItem);
- AdoptMenuItemLast(ev, menuItem);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivInitialize
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivInitialize(Environment* ev, const FW_CString& menuTitle)
- {
- FW_UNUSED(ev);
- fMenuBar = NULL;
- fParentMenuItem = NULL;
-
- fItems = FW_NEW(FW_TOrderedCollection<FW_CMenuItem>, ());
-
- #ifdef FW_BUILD_MAC
- Str255 str;
- menuTitle.ExportPascal(str);
- fPlatformMenu = ::NewMenu(fMenuID, str);
- #endif
-
- #ifdef FW_BUILD_WIN
- fPlatformMenu.menu = ::CreatePopupMenu();
- menuTitle.ExportCString(fPlatformMenu.strMenu);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::~FW_CPullDownMenu
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu::~FW_CPullDownMenu()
- {
- if (fItems)
- {
- FW_CMenuItem* item;
- while ((item = fItems->First()) != NULL)
- {
- fItems->Remove(item);
- delete item;
- }
-
- delete fItems;
- fItems = NULL;
- }
-
- #ifdef FW_BUILD_MAC
- if (fPlatformMenu)
- {
- ::DisposeMenu(fPlatformMenu);
- fPlatformMenu = NULL;
- }
- #endif
-
- #ifdef FW_BUILD_WIN
- if (fPlatformMenu.menu)
- {
- ::DestroyMenu(fPlatformMenu.menu);
- fPlatformMenu.menu = NULL;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendTextItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendTextItem(Environment* ev,
- const FW_CString& text,
- ODCommandID commandID,
- FW_MenuKey menuKey)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = FW_NEW(FW_CTextItem, (ev, this, index, text, commandID, menuKey));
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertTextItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertTextItem(Environment* ev,
- const FW_CString& text,
- ODCommandID commandID,
- short afterItem,
- FW_MenuKey menuKey)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = FW_NEW(FW_CTextItem, (ev, this, index, text, commandID, menuKey));
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertTextItemAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertTextItemAfterCommand(Environment* ev,
- const FW_CString& text,
- ODCommandID commandID,
- ODCommandID afterCommand,
- FW_MenuKey menuKey)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertTextItem(ev, text, commandID, item->GetIndex(ev), menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendToggleItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendToggleItem(Environment* ev,
- const FW_CString& trueText,
- const FW_CString& falseText,
- ODCommandID commandID,
- FW_MenuKey menuKey)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = FW_NEW(FW_CToggleItem, (ev, this, index, trueText, falseText, commandID, menuKey));
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertToggleItem
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertToggleItem(Environment* ev,
- const FW_CString& trueText,
- const FW_CString& falseText,
- ODCommandID commandID,
- short afterItem,
- FW_MenuKey menuKey)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = FW_NEW(FW_CToggleItem, (ev, this, index, trueText, falseText, commandID, menuKey));
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertToggleItemAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertToggleItemAfterCommand(Environment* ev,
- const FW_CString& trueText,
- const FW_CString& falseText,
- ODCommandID commandID,
- ODCommandID afterCommand,
- FW_MenuKey menuKey)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertToggleItem(ev, trueText, falseText, commandID, item->GetIndex(ev), menuKey);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendSubMenu
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendSubMenu(Environment* ev,
- FW_CPullDownMenu* adoptSubMenu)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = FW_NEW(FW_CSubMenuItem, (ev, this, index, adoptSubMenu));
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSubMenu
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSubMenu(Environment* ev,
- FW_CPullDownMenu* adoptSubMenu,
- short afterItem)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = FW_NEW(FW_CSubMenuItem, (ev, this, index, adoptSubMenu));
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSubMenuAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSubMenuAfterCommand(Environment* ev,
- FW_CPullDownMenu* adoptSubMenu,
- ODCommandID afterCommand)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertSubMenu(ev, adoptSubMenu, item->GetIndex(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AppendSeparator
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AppendSeparator(Environment* ev)
- {
- short index = CountItems(ev) + 1;
- FW_CMenuItem* menuItem = FW_NEW(FW_CSeparatorItem, (ev, this, index));
- this->AdoptMenuItemLast(ev, menuItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSeparator
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSeparator(Environment* ev,
- short afterItem)
- {
- if (afterItem > CountItems(ev))
- afterItem = CountItems(ev);
-
- short index = afterItem + 1;
-
- FW_CMenuItem* menuItem = FW_NEW(FW_CSeparatorItem, (ev, this, index));
- this->AdoptMenuItemAfter(ev, menuItem, afterItem);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::InsertSeparatorAfterCommand
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::InsertSeparatorAfterCommand(Environment* ev,
- ODCommandID afterCommand)
- {
- FW_CMenuItem* item = this->PrivGetMenuItem(ev, afterCommand);
- this->InsertSeparator(ev, item->GetIndex(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::RemoveItem
- //
- // If an index greater than the number of items in the menu is specified,
- // the last item is deleted.
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::RemoveItem(Environment* ev, short position)
- {
- FW_ASSERT(position > 0);
-
- if (position > CountItems(ev))
- position = CountItems(ev);
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- FW_CMenuItem* itemToRemove = NULL;
-
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- short index = item->GetIndex(ev);
-
- if (index == position)
- itemToRemove = item;
- else if (index > position)
- // if the current item is beneath the new item in the menu...
- {
- item->PrivSetIndex(ev, index - 1);
-
- #ifdef FW_BUILD_MAC
- if (fMenuBar != NULL) // need to unregister and re-register the item
- {
- fMenuBar->PrivMacUnregisterCommand(ev, item->GetCommandID(ev));
- fMenuBar->PrivMacRegisterCommand(ev, item->GetCommandID(ev), fMenuID, index - 1);
- }
- #endif
- }
- }
-
- FW_ASSERT(itemToRemove);
- fItems->Remove(itemToRemove);
-
- if (fMenuBar != NULL)
- itemToRemove->PrivDetach(ev, fMenuBar);
-
- // now, actually delete the item
-
- #ifdef FW_BUILD_MAC
- DeleteMenuItem(fPlatformMenu, position);
- #endif
-
- #ifdef FW_BUILD_WIN
- DeleteMenu(fPlatformMenu.menu, position - 1, MF_BYPOSITION);
- #endif
-
- delete itemToRemove;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AdoptMenuItemLast
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::AdoptMenuItemLast(Environment* ev, FW_CMenuItem* menuItem)
- {
- fItems->AddLast(menuItem);
-
- if (fMenuBar != NULL)
- menuItem->PrivAttach(ev, fMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::AdoptMenuItemAfter
- //----------------------------------------------------------------------------------------
- // If afterItem is greater than the number of items in the menu, the item is added to
- // then bottom of the menu; if it's zero, the item is added to the top.
-
- void FW_CPullDownMenu::AdoptMenuItemAfter(Environment* ev, FW_CMenuItem* menuItem, short afterItem)
- {
- FW_ASSERT(afterItem >= 0 && afterItem <= CountItems(ev));
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- FW_CMenuItem* prevItem = NULL;
-
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- short index = item->GetIndex(ev);
-
- if (index == afterItem)
- prevItem = item;
- else if (index > afterItem)
- // if the current item is beneath the new item in the menu...
- {
- item->PrivSetIndex(ev, index + 1); // adjust item numbers
-
- #ifdef FW_BUILD_MAC
- if (fMenuBar != NULL) // need to unregister and re-register the item
- {
- fMenuBar->PrivMacUnregisterCommand(ev, item->GetCommandID(ev));
- fMenuBar->PrivMacRegisterCommand(ev, item->GetCommandID(ev), fMenuID, index + 1);
- }
- #endif
- }
- }
-
- if (afterItem == 0) // add the item to the menu
- fItems->AddFirst(menuItem);
- else
- {
- FW_ASSERT(prevItem);
- fItems->AddAfter(prevItem, menuItem);
- }
-
- if (fMenuBar != NULL)
- menuItem->PrivAttach(ev, fMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::GetCommandID
- //----------------------------------------------------------------------------------------
- // returns FW_kNoCommand if not found or submenu, FW_kSeparatorCommand if separator
-
- ODCommandID FW_CPullDownMenu::GetCommandID(Environment* ev, short position) const
- {
- #ifdef FW_BUILD_MAC
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- if (item->GetIndex(ev) == position)
- return item->GetCommandID(ev);
- }
-
- return FW_kNoCommand;
- #endif
-
- #ifdef FW_BUILD_WIN
- return ::GetMenuItemID(fPlatformMenu.menu, position-1); // zero-based on windows
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivGetMenuItem
- //----------------------------------------------------------------------------------------
-
- FW_CMenuItem* FW_CPullDownMenu::PrivGetMenuItem(Environment* ev, ODCommandID commandID) const
- {
- FW_ASSERT(commandID != FW_kNoCommand);
- FW_ASSERT(commandID != FW_kSeparatorCommand);
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- if (item->GetCommandID(ev) == commandID)
- return item;
- else
- {
- FW_CMenuItem* subItem = item->PrivGetMenuItem(ev, commandID);
- if (subItem != NULL)
- return subItem;
- }
-
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivFindMenuWithID
- //----------------------------------------------------------------------------------------
-
- FW_CPullDownMenu* FW_CPullDownMenu::PrivFindMenuWithID(Environment* ev, ODMenuID menuID) const
- {
- FW_ASSERT(IsAttachedToMenuBar(ev)); // Otherwise it doesn't make sense because menuID
- // are only assigned when the menu is attached
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- FW_CPullDownMenu* subMenu = item->PrivFindMenuWithID(ev, menuID);
- if (subMenu != NULL)
- return subMenu;
- }
-
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::DisableAll
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::DisableAll(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- // ----- On the Mac disable all the items at once
- // [MEB] If enableFlags is set to 0, then menus with enabled items may be disabled.
- // That's because DisableAll is called first, and then menu items are enabled one by one.
- // When a menu item is enabled using FW_CMenuBar::EnableCommand et al, no check is made
- // to make sure its menu is enabled as well.
- (*fPlatformMenu)->enableFlags = 0x00000001;
- #endif
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- item->PrivDisableAll(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::EnableAll
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::EnableAll(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- // ----- On the Mac enable all the items at once
- (*fPlatformMenu)->enableFlags = 0xFFFFFFFF;
- #endif
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- item->PrivEnableAll(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivAcquireMenuID
- //----------------------------------------------------------------------------------------
-
- ODMenuID FW_CPullDownMenu::PrivAcquireMenuID(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuID == FW_kUnattachedMenuID);
- fMenuID = menuBar->PrivGetNewMenuID(ev);
- #ifdef FW_BUILD_MAC
- (*fPlatformMenu)->menuID = fMenuID;
- #endif
- return fMenuID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivRelinquishMenuID
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivRelinquishMenuID(Environment* ev)
- {
- FW_UNUSED(ev);
- FW_ASSERT(fMenuID != FW_kUnattachedMenuID);
- fMenuID = FW_kUnattachedMenuID;
- #ifdef FW_BUILD_MAC
- (*fPlatformMenu)->menuID = FW_kUnattachedMenuID;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivAttach
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivAttach(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuBar == NULL);
- fMenuBar = menuBar;
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- item->PrivAttach(ev, menuBar);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivDetach
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivDetach(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_ASSERT(fMenuBar == menuBar);
- fMenuBar = NULL;
-
- FW_TOrderedCollectionIterator<FW_CMenuItem> ite(fItems);
- for (FW_CMenuItem* item = ite.First(); ite.IsNotComplete(); item = ite.Next())
- {
- item->PrivDetach(ev, menuBar);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivAttachedToMenuBar
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivAttachedToMenuBar(Environment* ev, ODPart* part, FW_CMenuBar* menuBar, ODMenuID beforeID)
- {
- FW_ASSERT(menuBar != NULL);
- FW_ASSERT(fMenuBar == NULL);
- FW_ASSERT(fMenuID == FW_kUnattachedMenuID);
-
- PrivAcquireMenuID(ev, menuBar);
-
- FW_CAcquiredODMenuBar aqODMenuBar = menuBar->AcquireODMenuBar(ev);
-
- if (beforeID == -1)
- {
- #ifdef FW_BUILD_WIN
- // [WIN_PORT]: AddMenuLast takes an ODPlatformMenu* in OD/Win -- different from OD/Mac
- aqODMenuBar->AddMenuLast(ev, fMenuID, &fPlatformMenu, part);
- #else
- aqODMenuBar->AddMenuLast(ev, fMenuID, fPlatformMenu, part);
- #endif
- }
- else
- {
- #ifdef FW_BUILD_WIN
- // [WIN_PORT]: AddMenuBefore takes an ODPlatformMenu* in OD/Win -- different from OD/Mac
- aqODMenuBar->AddMenuBefore(ev, fMenuID, &fPlatformMenu, part, beforeID);
- #else
- aqODMenuBar->AddMenuBefore(ev, fMenuID, fPlatformMenu, part, beforeID);
- #endif
- }
-
- PrivAttach(ev, menuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::PrivDetachedFromMenuBar
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::PrivDetachedFromMenuBar(Environment* ev, FW_CMenuBar* menuBar)
- {
- FW_UNUSED(menuBar);
- FW_ASSERT(fMenuBar != NULL);
- FW_ASSERT(fMenuBar == menuBar);
-
- fMenuBar->PrivRemoveMenu(ev, fMenuID);
-
- PrivDetach(ev, fMenuBar);
-
- PrivRelinquishMenuID(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPullDownMenu::Flatten
- //----------------------------------------------------------------------------------------
-
- void FW_CPullDownMenu::Flatten(Environment* ev, FW_CWritableStream& stream) const
- {
- //----- Save menu data -----
- FW_CString menuTitle;
- short count = CountItems(ev);
-
- #ifdef FW_BUILD_MAC
- menuTitle.ReplaceAll((*fPlatformMenu)->menuData);
- FW_ASSERT(count == ::CountMItems(fPlatformMenu));
- #endif
- #ifdef FW_BUILD_WIN
- menuTitle = fPlatformMenu.strMenu;
- FW_ASSERT(count == ::GetMenuItemCount(fPlatformMenu.menu));
- #endif
-
- stream << menuTitle;
- stream << count;
-
- //----- Save menu items -----
- FW_TOrderedCollectionIterator<FW_CMenuItem> itemIter(fItems);
- for (FW_CMenuItem* menuItem = itemIter.First(); itemIter.IsNotComplete(); menuItem = itemIter.Next())
- {
- FW_WRITE_DYNAMIC_OBJECT(stream, menuItem, FW_CMenuItem);
- }
- }
-